AllKinds tests: cargo-bench, cargo-build
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>
Wed, 5 Apr 2017 18:50:22 +0000 (20:50 +0200)
committerBen Wiederhake <BenWiederhake.GitHub@gmx.de>
Mon, 10 Apr 2017 18:20:32 +0000 (20:20 +0200)
tests/bench.rs
tests/build.rs

index fdb16f3705bd3be3715fa658688e0120bb0cb9b2..a03fe512a839e6f2e18fc56276026123fef634fe 100644 (file)
@@ -53,6 +53,88 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
 "));
 }
 
+#[test]
+fn bench_bench_implicit() {
+    if !is_nightly() { return }
+
+    let prj = project("foo")
+        .file("Cargo.toml" , r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/main.rs", r#"
+            #![feature(test)]
+            extern crate test;
+            #[bench] fn run1(_ben: &mut test::Bencher) { }
+            fn main() { println!("Hello main!"); }"#)
+        .file("tests/other.rs", r#"
+            #![feature(test)]
+            extern crate test;
+            #[bench] fn run3(_ben: &mut test::Bencher) { }"#)
+        .file("benches/mybench.rs", r#"
+            #![feature(test)]
+            extern crate test;
+            #[bench] fn run2(_ben: &mut test::Bencher) { }"#);
+
+    assert_that(prj.cargo_process("bench").arg("--benches"),
+        execs().with_status(0)
+               .with_stderr(format!("\
+[COMPILING] foo v0.0.1 ({dir})
+[FINISHED] release [optimized] target(s) in [..]
+[RUNNING] target[/]release[/]deps[/]mybench-[..][EXE]
+", dir = prj.url()))
+               .with_stdout("
+running 1 test
+test run2 ... bench: [..] 0 ns/iter (+/- 0)
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
+
+"));
+}
+
+#[test]
+fn bench_bin_implicit() {
+    if !is_nightly() { return }
+
+    let prj = project("foo")
+        .file("Cargo.toml" , r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/main.rs", r#"
+            #![feature(test)]
+            extern crate test;
+            #[bench] fn run1(_ben: &mut test::Bencher) { }
+            fn main() { println!("Hello main!"); }"#)
+        .file("tests/other.rs", r#"
+            #![feature(test)]
+            extern crate test;
+            #[bench] fn run3(_ben: &mut test::Bencher) { }"#)
+        .file("benches/mybench.rs", r#"
+            #![feature(test)]
+            extern crate test;
+            #[bench] fn run2(_ben: &mut test::Bencher) { }"#);
+
+    assert_that(prj.cargo_process("bench").arg("--bins"),
+        execs().with_status(0)
+               .with_stderr(format!("\
+[COMPILING] foo v0.0.1 ({dir})
+[FINISHED] release [optimized] target(s) in [..]
+[RUNNING] target[/]release[/]deps[/]foo-[..][EXE]
+", dir = prj.url()))
+               .with_stdout("
+running 1 test
+test run1 ... bench: [..] 0 ns/iter (+/- 0)
+
+test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
+
+"));
+}
+
 #[test]
 fn bench_tarname() {
     if !is_nightly() { return }
index 1eea86b5cb2c26c7e94963e6d7570a7d518c6f4b..325d0e81c508771a1a44e52bd2d3a1b6b3e0c0d9 100644 (file)
@@ -2215,6 +2215,54 @@ fn filtering() {
     assert_that(&p.bin("examples/b"), is_not(existing_file()));
 }
 
+#[test]
+fn filtering_implicit_bins() {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/lib.rs", "")
+        .file("src/bin/a.rs", "fn main() {}")
+        .file("src/bin/b.rs", "fn main() {}")
+        .file("examples/a.rs", "fn main() {}")
+        .file("examples/b.rs", "fn main() {}");
+    p.build();
+
+    assert_that(p.cargo("build").arg("--bins"),
+                execs().with_status(0));
+    assert_that(&p.bin("a"), existing_file());
+    assert_that(&p.bin("b"), existing_file());
+    assert_that(&p.bin("examples/a"), is_not(existing_file()));
+    assert_that(&p.bin("examples/b"), is_not(existing_file()));
+}
+
+#[test]
+fn filtering_implicit_examples() {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/lib.rs", "")
+        .file("src/bin/a.rs", "fn main() {}")
+        .file("src/bin/b.rs", "fn main() {}")
+        .file("examples/a.rs", "fn main() {}")
+        .file("examples/b.rs", "fn main() {}");
+    p.build();
+
+    assert_that(p.cargo("build").arg("--examples"),
+                execs().with_status(0));
+    assert_that(&p.bin("a"), is_not(existing_file()));
+    assert_that(&p.bin("b"), is_not(existing_file()));
+    assert_that(&p.bin("examples/a"), existing_file());
+    assert_that(&p.bin("examples/b"), existing_file());
+}
+
 #[test]
 fn ignore_dotfile() {
     let p = project("foo")